/*
 * @Description: 群聊
 * @Author: fhw
 * @Date: 2022-11-18 11:13:34
 */
import { ApiProperty } from '@nestjs/swagger';
import { GroupChatRecord } from 'src/chat-record/entities/group-chat-record.entity';
import { ChatUserGroup } from 'src/chat_user_group/entities/chat_user_group.entity';
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryColumn,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { ChatUser } from '../../chat_user/entities/chat_user.entity';

@Entity('chat_group')
export class GroupChat {
  @ApiProperty({ example: 'group_id', description: '群id' })
  @PrimaryGeneratedColumn('uuid')
  group_id: string;

  @ApiProperty({ example: 'groupChatName', description: '群名称' })
  @Column({
    type: 'varchar',
    length: 255,
    comment: '群名称',
  })
  groupChatName: string;

  @ApiProperty({ example: 'date', description: '创建时间' })
  @CreateDateColumn({
    type: 'datetime',
    comment: '创建时间',
  })
  createDate: string;

  @ApiProperty({ example: 'updateDate', description: '更新时间' })
  @UpdateDateColumn({
    type: 'datetime',
    comment: '更新时间',
  })
  updateDate: string;

  @ApiProperty({ example: 'announcement', description: '公告' })
  @Column({
    type: 'varchar',
    length: 255,
    comment: '公告',
    nullable: true,
  })
  announcement: string;

  @ApiProperty({ example: 'group_portrait', description: '群头像' })
  @Column({
    type: 'varchar',
    length: 255,
    comment: '群头像',
    nullable: true,
  })
  group_portrait: string;

  @ApiProperty({ example: 'managerId', description: '群主ID' })
  @Column({
    type: 'int',
    comment: '群主ID',
  })
  managerId: number;

  @ManyToOne(() => ChatUser, (user) => user.id)
  @JoinColumn()
  manager: ChatUser;
  
  @OneToMany(() => ChatUserGroup, (avatar) => avatar.id)
  chatUserGroup: ChatUserGroup;

   /** 最新消息Id */
   @ApiProperty({ example: 'latestNewsId', description: '最新消息Id' })
   @Column({
     type: 'tinyint',
     comment: '最新消息Id',
     nullable: true
   })
   latestNewsId: number
   @ManyToOne(() => GroupChatRecord, (latestNews) => latestNews.id, { nullable: true, eager: true })
   @JoinColumn({ name: 'latestNewsId' })
   latestNews: GroupChatRecord
}
export class GroupChatResult extends GroupChat {
  @ApiProperty({
    example: GroupChat,
    type: [GroupChat],
  })
  data: GroupChat[]
  @ApiProperty({ example: 'pageSize', description: '数量' })
  pageSize: number
  @ApiProperty({ example: 'pageNum', description: '页数' })
  pageNum: number
  @ApiProperty({ example: 'total', description: '总数' })
  total: number
}
